<?php

namespace app\api\controller\v2;

use app\common\controller\Api;

/**
 * 配置项目接口
 */
class Config extends Api
{
    //无需登录的方法,同时也就不需要鉴权了
    protected $noNeedLogin = ['getWebConfig'];
    //无需鉴权的方法,但需要登录
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();

        if (!\think\Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }

    }

    //获取网站配置项
    public function getWebConfig(){
        $name = [
            'name',//网站名称
            'beian',//网站备案号
            'record_number_query_link',//网站备案号查询链接
            'icp',//ICP备案
            'icp_query_link',//ICP查询链接
            'logo',//网站logo
            'score_rule',//积分规则
            'service_agreement',//用户服务协议
            'service_agreement_text',//用户服务协议
            'service_tel',//客服电话
            'sidebar_as_1',//直播预告别名
            'sidebar_as_5',//小道消息别名
        ];
        $config = \app\common\model\Config::whereIn('name',$name)->column('value','name');
        $res = [];
        foreach ($config as $k=>$v){
            $res['web_' . $k] = $v;
        }
        if ($res['web_logo']) {
            if (substr($res['web_logo'], 0, 1) === '/') {
                $res['web_logo'] = obsurl($res['web_logo']);
            }
        }
        $res['web_service_agreement'] = obsurl($config['service_agreement']);//用户服务协议(PDF版本)
        $res['web_service_agreement_text'] = $config['service_agreement_text'];//用户服务协议文字版本
        $res['web_service_tel'] = $config['service_tel'];//客服电话

        $res['web_qa_community_channels_id'] = \app\common\model\Config::where('name', 'plate_post_channels_id')->value('value') ?? 18;//获取快速发帖分类id(债市论坛发帖直达),fa_channels表id

        $res['web_plate_post_quora_channels_id'] = \app\common\model\Config::where('name', 'plate_post_quora_channels_id')->value('value') ?? 19;//获取问答社区快速发帖分类idfa_channels表id

        $res['web_is_mini_wechat_show'] = \app\common\model\Config::where('name', 'is_mini_wechat_show')->value('value') ?? 0;//是否展示小程序隐藏项|0=否,1=是

        //IM置顶官方群组id
        $res['top_im_user_chat_groups_id'] = \app\common\model\Config::where('name', 'top_im_user_chat_groups_id')->value('value') ?? 1;

        $this->success('',$res);
    }



}
